package com.knight.thread;

import java.util.concurrent.TimeUnit;

import ch.qos.logback.core.util.TimeUtil;

public class TestSynchronized {
	
	String LOCK1 = new String("LOCK");
	String LOCK2 = new String("LOCK");
	
	String LOCK3 = "LOCK";
	String LOCK4 = "LOCK";
	void m1() {
		synchronized(LOCK3){
			try {
				TimeUnit.SECONDS.sleep(10);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	
	void m2() {
		synchronized(LOCK4){
			System.out.println("lock2");
		}
	}

	public static void main(String[] args) {
			
		TestSynchronized test = new TestSynchronized();
		
		
		new Thread(test::m1).start();
		
		try {
			TimeUnit.MILLISECONDS.sleep(1000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		new Thread(test::m2).start();
		
		new Thread(()->test.m2()).start();

	}

}
